Everything about Bitmaps

By: Rohan Varma and Boice Wong

Introduction

This tutorial will teach you about bitmaps(images). First it will teach you how to load a bitmap and draw it on a screen. Then it will show you how to get that image to move around on the screen. Next, it will illustrate how to get the image to appear wherever the user touches the screen. Finally, the tutorial will demonstrate how to animate a sprite. The different sections of the tutorial use the same code, so they should all be done in the same project.

Drawing an Image on the Screen

https://lh4.googleusercontent.com/7zQAfUKVfnSPBB0rD7Cl7BPVvYtFqcAyfhNQ8yjPffT7300Jgvbg0WQgeKjbcltlye6HR6cEKVwdKK4RWwIfhQyHsrCDUL8wkO0rLL-Lps1IUhR4rppkNgyyHxlHcY8GTnlhUSaj

https://lh6.googleusercontent.com/vBoQ_acosKmTbgwjXy_9yj6M2fNQklaAeGeG-GWT67fGdgai1rlxSfn1E2PuXhm1r09bZrWKI1X29TCqxmFTVVKk_yT8mNwNuUJ8zXmeqvVO2OngAQby1hy6XgmA5DT558Hwc-J8


https://lh3.googleusercontent.com/_uNOlmgE2dEODHyg38BYqSAp2iVYUaP7t3lFXmprdtHHH-aUE0K7jcI4eJhOzrLkIr1bLIO3VdwRvhkrj9qUyP4POR9sx2oe7WHDcF88E1T7eManet8eO6RvDNkm956oqJweUFrI



https://lh6.googleusercontent.com/9BA6-exg8QukCfO9ZgJf3aetYGtXV5e5XiQgoMsMl82cbRAOCB3F76LvKKi4htoYPgvush7qvewYRMKXaiQaLEWX9mRdm5mhu681HdMD0wSadg53DOgoI9Cuj1Ws75fNCQse79p6

In order to set up the Rect, add the following line of code. The 4 values in the parentheses are the coordinates for where the left, top, right, and bottom of the rectangle will be on the screen.

https://lh5.googleusercontent.com/leCVt1JZPbkdOOqHrSfE1p5GdNOJ7MxzeTkuV_S2hIuH1PjpGqt4Mx6w8e-2mjV4Ac3hEjzbQTP1ILQWnVpV6AHezvvm3PWrRgcUHLp9Tpv9uKO1DOroNwepbvAQISfH413bdtYB

Now, when you run the app, it will draw an image on the screen. When making a game you could potentially reset the Rects coordinates in the Update method and have images move around! If you want to learn how to do that, keep scrolling down.

 

Making a Bitmap Move

          https://lh5.googleusercontent.com/MdznLBT9pZ-_pIKcrsvgSYxFQSR2jb28WPpus6LNC7pOmLKH49P6DHI_OCN4BeUTMkBCjQsXIg3Vs6tABeI7nvL97HGqCGVqkjtk66hJ-Jhk8szgP9wd-ZcE4dXFu5agd7wtspBF

Make sure you put this in the Update() method !!!!! If you run the program at this point, you should have an image that moves off the screen. If the image is too slow or fast, you can either adjust xSpeed or ySpeed, or change the long in the try catch statement in update

https://lh6.googleusercontent.com/y2PkA94BS_bTiYr8-gIknGjqHDDP1-C5WABOQka8tiOt4QwdIpiWULJWbEFyUFhgzfPnSmlC901e0kshbUUqCR6fOilL9amopXQrzOAcy52-NKojdZNMNYKtfYpHKibJX9gFE03F

 

.


https://lh4.googleusercontent.com/OzheBsmiI_YED4sTCbles4FlcGkUSeoRcQc9HR4xQukHpGcKxnagX7GhG2Ob08-NUgHPBTxSstpxbCNW3EvOD-P-sjzMEhaAKxisRQYOmZi840_vOCC4LW863x4RhKCPVP18fOy1


 

Getting the Image to Appear Where the User Touches the Screen

https://lh5.googleusercontent.com/LQD2XLHezemKn-wOjX98-qVJuTsSU6zbOybadoPRetoAXNUg2zzmZUxVU1t97bIpf8px1HXtNcf8OPFsNX8dGpL1ipep7yitxUpczjvjQaJA5rA0WKfVSuDuFDd1aL1RWQchKCcP

Animating a Sprite

monster.png